<template>
  <a-layout class="web-header">
    <a-layout-header class="header">
      <div class="logo" :class="{ 'logo-collapsed': collapsed }">
        <img :src="logo" /><span v-if="!collapsed">{{ title }}</span>
      </div>
      <a-menu
        v-model="activeMenu"
        @select="onSelected"
        theme="light"
        mode="horizontal"
        :style="{ lineHeight: '64px' }"
      >
        <a-menu-item key="/">
          首页
        </a-menu-item>
        <a-menu-item key="/web">
          门户网站
        </a-menu-item>
        <a-menu-item key="/console">
          后台管理
        </a-menu-item>
        <a-menu-item key="/examples">
          工具用例
        </a-menu-item>
      </a-menu>
    </a-layout-header>
  </a-layout>
</template>
<script>
import config from "@/config";

export default {
  name: "WebHeader",
  data() {
    return {
      logo: config.logo,
      title: config.title,
      collapsed: false,
      activeMenu: []
    };
  },
  watch: {
    $route() {
      this.activeMenu = [this.$route.path];
    }
  },
  created() {
    this.activeMenu = [this.$route.path];
  },
  methods: {
    onSelected(item) {
      this.$router.push(`${item.key}`);
    }
  }
};
</script>

<style scoped lang="less">
.web-header {
  .header {
    background: #ffffff;
  }

  .logo {
    width: 150px;
    height: 32px;
    margin: 16px;
    display: flex;
    align-items: center;
    color: white;
    float: left;

    img {
      width: 30px;
      height: 30px;
    }

    span {
      margin-left: 20px;
      color: @heading-color;
    }
  }
}
</style>
